import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-02-16
 * Time: 13:07
 */
public class test3 {
    /**
     * LeetCode  49  字母异位词分组
     */

    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String,List<String>> hash = new HashMap<>();
        // 1.先把所有字母异位词分组
        for(String str:strs){
            char[] array = str.toCharArray();
            // 排序
            Arrays.sort(array);
            String key = new String(array);
            if(!hash.containsKey(key)){
                hash.put(key,new ArrayList());
            }
            hash.get(key).add(str);
        }
        return new ArrayList(hash.values());
    }
}
